package com.ruoyi.print.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.print.mapper.CustomerProviderMapper;
import com.ruoyi.print.domain.CustomerProvider;
import com.ruoyi.print.service.ICustomerProviderService;

/**
 * 自定义providerService业务层处理
 *
 * @author korol
 * @date 2023-11-06
 */
@Service
public class CustomerProviderServiceImpl extends ServiceImpl<CustomerProviderMapper, CustomerProvider> implements ICustomerProviderService {

    @Autowired
    private CustomerProviderMapper customerProviderMapper;

    /**
     * 查询自定义provider列表
     *
     * @param customerProvider 自定义provider
     * @return 自定义provider
     */
    @Override
    public List<CustomerProvider> selectCustomerProviderList(CustomerProvider customerProvider)
    {
        List<CustomerProvider> customerProviderList = customerProviderMapper.selectList(buildQueryWrapper(customerProvider));
        return customerProviderList;
    }


    private LambdaQueryWrapper<CustomerProvider> buildQueryWrapper(CustomerProvider query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<CustomerProvider> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getName()), CustomerProvider::getName, query.getName());
        lqw.eq(StringUtils.isNotBlank(query.getType()), CustomerProvider::getType, query.getType());
        lqw.orderByDesc(CustomerProvider::getCreateTime);
        return lqw;
    }

}
